/* PR c/102989 */
/* { dg-do run { target bitint } } */
/* { dg-options "-std=c23 -pedantic-errors" } */
/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */

#if __BITINT_MAXWIDTH__ >= 128
__attribute__((noipa)) void
foo (_BitInt(125) a, _BitInt(128) b, _BitInt(125) *p, _BitInt(128) *q, float c)
{
  p[0] = b;
  q[0] = a;
  q[1] = (unsigned _BitInt(125)) a;
  q[2] = (unsigned _BitInt(68)) a;
  q[3] = c;
  q[4] += a;
  q[5] = a + b;
  q[6] = a - b;
  q[7] = a * b;
  q[8] = a / b;
  q[9] = a % b;
  q[10] = b << (-80694244678005661015504159217709wb - a);
  q[11] = a >> (-80694244678005661015504159217709wb - a);
  q[12]++;
  ++q[13];
  q[14]--;
  --q[15];
  q[16] = a == b;
  q[17] = a != b;
  q[18] = a > b;
  q[19] = a < b;
  q[20] = a >= b;
  q[21] = a <= b;
  q[22] = a && b;
  q[23] = a || b;
  q[24] = !a;
  q[25] = a & b;
  q[26] = a | b;
  q[27] = a ^ b;
  q[28] = ~a;
  q[29] -= a;
  q[30] *= b;
  q[31] /= b;
  q[32] %= a;
  q[33] <<= (b - 468021wb);
  q[34] >>= (b - 468021wb);
  q[35] &= a;
  q[36] |= b;
  q[37] ^= a;
  q[38] = sizeof (a);
  q[39] = q[39] ? a : b;
  q[40] = 80694244678005661015504159217732wb;
  switch (a)
    {
    case 313298472398574896574578475487548wb:
      if (b != 813298738947385454wb)
	__builtin_abort ();
      break;
    case -18198347584784758927893783748374wb:
      if (b != 9439847384738wb)
	__builtin_abort ();
      break;
    case 261243875485748189278344574857484wb:
      if (b != 12549857489574wb)
	__builtin_abort ();
      break;
    case -80694244678005661015504159217733wb:
      if (b != 468071wb)
	__builtin_abort ();
      break;
    case -193984372895748547584754854wb:
      if (b != 15549857489574wb)
	__builtin_abort ();
      break;
    default:
      __builtin_abort ();
    }
}

int
main ()
{
  _BitInt(125) p;
  _BitInt(128) q[41];
  static _BitInt(128) qe[41] = {
     -80694244678005661015504159217733wb, 42535215170872629927260810424811808699wb,
     211591633426360068027wb, -42wb,
     -80694244678005661015504143312912wb, -80694244678005661015504158749662wb,
     -80694244678005661015504159685804wb, -37770635800678787757188047309203503043wb,
     -172397445426026523786998466wb, -238647wb,
     7852928270336wb, -4809751789450982869595538wb,
     821095840985901334959wb, 13895798174897154898wb,
     1465897921835729857453wb, 154987847598437549873142wb,
     0, 1, 0, 1, 0, 1, 1, 1, 0,
     271395wb, -80694244678005661015504159021057wb,
     -80694244678005661015504159292452wb, 80694244678005661015504159217732wb,
     80694244678240648474427914115297wb, -5822736520666880936123wb,
     9818355413803wb, 54398547589478975845wb,
     39390147499089156967386811811758080wb, 30486wb,
     5910462358441918751905wb, 1342984375894755194479wb,
     -80694244535621434450947930710749wb, 1, -80694244678005661015504159217733wb,
     80694244678005661015504159217732wb
  };
  q[4] = 15904821wb;
  q[12] = 821095840985901334958wb;
  q[13] = 13895798174897154897wb;
  q[14] = 1465897921835729857454wb;
  q[15] = 154987847598437549873143wb;
  q[29] = 234987458923754897564wb;
  q[30] = -12439857458947213wb;
  q[31] = 4595687436894573685wb;
  q[32] = 54398547589478975845wb;
  q[33] = 34985478957495847545wb;
  q[34] = 34324329847328473343wb;
  q[35] = 5984758947589437584545wb;
  q[36] = 1342984375894754857545wb;
  q[37] = 159847589475894768597656wb;
  q[39] = 394857584wb;
  foo (-80694244678005661015504159217733wb, 468071wb, &p, q, -42.0f);
  if (p != 468071wb)
    __builtin_abort ();
  q[38] -= sizeof (p) - 1;
  for (int i = 0; i < 41; ++i)
    if (q[i] != qe[i])
      __builtin_abort ();
  return 0;
}
#else
int
main ()
{
  return 0;
}
#endif
